package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysReserveLog;
import com.ruoyi.system.service.ISysReserveLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预约记录Controller
 * 
 * @author ruoyi
 * @date 2019-09-02
 */
@Controller
@RequestMapping("/system/reserve")
public class SysReserveLogController extends BaseController
{
    private String prefix = "system/reserve";

    @Autowired
    private ISysReserveLogService sysReserveLogService;

    @RequiresPermissions("system:reserve:view")
    @GetMapping()
    public String reserve()
    {
        return prefix + "/reserve";
    }

    /**
     * 查询预约记录列表
     */
    @RequiresPermissions("system:reserve:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysReserveLog sysReserveLog)
    {
        startPage();
        List<SysReserveLog> list = sysReserveLogService.selectSysReserveLogList(sysReserveLog);
        return getDataTable(list);
    }

    /**
     * 导出预约记录列表
     */
    @RequiresPermissions("system:reserve:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysReserveLog sysReserveLog)
    {
        List<SysReserveLog> list = sysReserveLogService.selectSysReserveLogList(sysReserveLog);
        ExcelUtil<SysReserveLog> util = new ExcelUtil<SysReserveLog>(SysReserveLog.class);
        return util.exportExcel(list, "reserve");
    }

    /**
     * 新增预约记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存预约记录
     */
    @RequiresPermissions("system:reserve:add")
    @Log(title = "预约记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysReserveLog sysReserveLog)
    {
        return toAjax(sysReserveLogService.insertSysReserveLog(sysReserveLog));
    }

    /**
     * 修改预约记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysReserveLog sysReserveLog = sysReserveLogService.selectSysReserveLogById(id);
        mmap.put("sysReserveLog", sysReserveLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存预约记录
     */
    @RequiresPermissions("system:reserve:edit")
    @Log(title = "预约记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysReserveLog sysReserveLog)
    {
        return toAjax(sysReserveLogService.updateSysReserveLog(sysReserveLog));
    }

    /**
     * 删除预约记录
     */
    @RequiresPermissions("system:reserve:remove")
    @Log(title = "预约记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysReserveLogService.deleteSysReserveLogByIds(ids));
    }
}
